// packageH/shareProfit/shareProfit.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    member: {},
    ion: "",
    active:0,
    isLoadMore:false,
    loading:false,
    listData:[],
    page:1,
    last_page:1
  },
  initData(){
    this.setData({
      page:1,
      listData:[],
      isLoadMore:false,
      loading:true,
      last_page:null
    })
  },
  $toast(title){
    wx.showToast({
      title,
      duration: 1000,
      icon: "none",
    })
  },
  getdata(){
    this.initData();
    app._postNetWork({
      url: app.getNetAddresss("plugin.member-synchron.frontend.assets.income-list"),
      data: {page: this.data.page},
      success: ({data:{result,msg,data}}) => {
        this.setData({loading:false});
        if(result == 1){
          this.setData({
            member:data.member,
            ion:data.ion,
            listData:data.income_list.data,
            last_page:data.income_list.last_page,
            isLoadMore:!(data.income_list.current_page == data.income_list.last_page)
          })
        }else this.$toast(msg);
      }
    })
  },
  getMoreData(){
    if(!this.data.isLoadMore){
      return this.$toast("没有更多了~~~");
    }
    let page = this.data.page + 1;
    this.setData({loading:true});
    app._postNetWork({
      url: app.getNetAddresss("plugin.member-synchron.frontend.assets.income-list"),
      data: {page},
      success: ({data:{result,msg,data}}) => {
        this.setData({loading:false});
        if(result == 1){
          this.setData({
            listData:this.data.listData.concat(data.income_list.data),
            page,
            isLoadMore:!(data.income_list.current_page == data.income_list.last_page)
          })
        }else this.$toast(msg)
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdata();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMoreData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})